{% extends "master.html" %}
{% block subtitle %} - 采购管理 - 创建采购单{% endblock %}

{% block extCSS %}
<style type="text/css">
    .atmtemplate{
        display : none;
    }
    
    .modal{
        width : 860px;
        margin-left: -460px;
    }
</style>
{% endblock %}

{% block extJS %}
<script src="{{url_for('static', filename='js/customize/purchase_add.js')}}" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
//<![CDATA[   
    var extPdts = [];

    $(document).ready(function(){
        $(".priceclz,.qtyclz").change(function(){
            countAmount();
        })        
    });
    

    function toSubmit(){
        var msg = [];
        clearMsg();
        $(".err").removeClass('err');
        
        
        if(!$("#supplierID").val()){
            msg.push('请选择供应商！');
            $("#supplierID").addClass('err');
        }
        
        
        var pflag = false;
        var qflag = true; 
        $("input[name^='product_']").each(function(){
            var t = $(this);
            if(t.val()){ 
                pflag = true; 
                var pid = t.attr('name').split("_")[1]
                if(!$("input[name='qty_"+pid+"']").val()){ qflag = false; }
                if(!$("input[name='realPrice_"+pid+"']").val()){ qflag = false; }
            }
        });
        
        if(!pflag){ msg.push('请填写至少一个商品名称！'); }
        if(!qflag){ msg.push('请填写商品的数量以及价格！'); }
        
        var flag = true;
        $(".num").each(function(){
            var t = $(this);
            if( t.val() && !check_number(t.val())){
                flag = false;
                t.addClass('err');
            }
        })
        
        if(!flag){
            msg.push('请正确填写数量以及价钱,只填写数字!')
        }
        
        if(msg.length > 0){
            alertError(msg);
            return false;
        }else{
            $("form").submit();
        }
    }
    
    function toCancel(){
        redirect_alert("{{MSG_LEAVE_WITHOUT_SAVING}}","{{url_for('bpPrh.view')}}")
    }        
        
//]]>
</script>
{% endblock %}


{% block main %}
<div class="container">
    <div class="row">
        <ol class="breadcrumb">
          <li><a href="{{url_for('bpRoot.view')}}">基础信息</a></li>
          <li><a href="{{url_for('bpPrh.view')}}">采购管理</a></li>
          <li class="active">创建采购单</li>
        </ol>
    </div>
    <div class="row">
        <div class="btn-toolbar pull-right">
            <div class="btn-group"><button class="btn btn-primary" onclick="toSubmit()">{{BTN_SUBMIT}}</button></div>
            <div class="btn-group"><button class="btn btn-inverse" onclick="toCancel()">{{BTN_CANCEL}}</button></div>
        </div>
    </div>
    <div class="row">
    <form class="" method='POST' action="{{url_for('bpPrh.view',action='add')}}" enctype="multipart/form-data">
        <fieldset>
            <legend>采购单详情</legend>
            <div class="col-md-4">
                <div class="control-group controls-row">
                    <label for="remark" class="control-label"><label for="supplierID">供应商<span style='color:red'>*</span></label></label>
                    <div class="controls">
                        <select id="supplierID" name="supplierID" onchange="changeSupplier()">
                            <option value=""></option>
                            {% for s in getMaster('Supplier') %}
                                <option value="{{s.id}}">{{s}}</option>
                            {% endfor %}
                        </select>
                        {% if getAllPermission(['SUPPLIER_CREATE',])%}
                            <a href="#" onclick="refreshMaster('supplierID','Supplier')"><i class="glyphicon glyphicon-refresh"></i></a>
                            <a target="_blank" href="{{url_for('bpSpl.view',action='add')}}"><i class="glyphicon glyphicon-plus"></i></a>
                        {% endif %}
                    </div>
                </div>
                <div class="control-group controls-row">
                    <label for="att" class="control-label"><label for="att">联系人<span style='color:red'>*</span></label></label>
                    <div class="controls"><input type="text" id="att" name="att" value=""/></div>
                </div>
                <div class="control-group controls-row">
                    <label for="tel" class="control-label"><label for="tel">联系电话<span style='color:red'>*</span></label></label>
                    <div class="controls"><input type="text" name="tel" id="tel" value=""/></div>
                </div>
                <div class="control-group controls-row">
                    <label for="mobile" class="control-label"><label for="mobile">联系手机<span style='color:red'>*</span></label></label>
                    <div class="controls"><input type="text" name="mobile" id="mobile" value=""/></div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="control-group controls-row">
                    <label for="createTime" class="control-label"><label for="createTime">采购日期</label></label>
                    <div class="controls"><input type="text" name="createTime" value="{{now()|fd}}" class="datepicker"/></div>
                </div>
                <div class="control-group controls-row">
                    <label for="createBy" class="control-label"><label for="createBy">经办人</label></label>
                    <div class="controls"><input type="text" name="createBy" value="{{session['user_profile']['name']}}" readonly="true"/></div>
                </div>
                <div class="control-group controls-row">
                    <label for="remark" class="control-label"><label for="remark">备注</label></label>
                    <div class="controls"><textarea name="remark" id="remark"></textarea></div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="control-group controls-row">
                    <label for="amount" class="control-label"><label for="amount">总金额<span style='color:red'>*</span></label></label>
                    <div class="controls"><input type="text" name="amount" id="amount" value="" class="num" readonly="true"/></div>
                </div>
                <div class="control-group">
                  <label class="control-label" for="attachment">附件</label>
                  <div class="controls">
                      <ul id="atmul" class="list-unstyled">
                          <li><input type="file" name="atm_10"/><a href="#" onclick="addAtm('atmtemplate','atmmk','#atmul')"><i class="glyphicon glyphicon-plus"></i></a></li>
                          <li class="atmtemplate"><input type="file" name="atm_x"/><a href="#" onclick="delAtm(this,'atmmk')"><i class="glyphicon glyphicon-minus"></i></a></li>
                      </ul>
                  </div>
                </div>
            </div>          
            <div class="col-md-12">
                <label>添加商品</label>
                <select id="field">
                    <option value="no">商品编号</option>
                    <option value="name">商品名称</option>
                </select>
                <input type="text" id="fieldValue" class="input-xxlarge" data-provide="typeahead" autocomplete="off" placeholder="请输入商品相关信息，回车添加商品并清空输入框信息"/>
                <table class="table table-bordered" id="pdt_tb">
                    <thead>
                        <tr>
                            <td>&nbsp;</td>
                            <td class="col-md-2">商品编号</td>
                            <td>商品名称</td>
                            <td>商品类型</td>
                            <td>商品价钱</td>
                            <td>采购价钱</td>
                            <td>数量</td>
                            <td>备注</td>
                        </tr>
                    </thead>
                    <tbody id="pdtlist">
    
                    </tbody>                
                </table>
            </div>
        </fieldset>            
                      
    </form>
    </div>
</div>


{{mymacros.render_recent_prh_price()}}

{% endblock %}